import { Component, Input, OnInit } from '@angular/core';
import {SFSchema, SFTreeSelectWidgetSchema} from '@delon/form';
import { NzMessageService, NzModalRef } from 'ng-zorro-antd';
import { AreaService } from '../../area.service';
import { _HttpClient } from '@delon/theme';
import { ApiService } from '@core/services/api';

@Component({
  selector: 'app-card-face-set',
  templateUrl: './card-face-set.component.html',
  styles: []
})
export class CardFaceSetComponent implements OnInit {
  @Input() 
   set _param(value){
     if(!value) return;
     this.id=value.id;
     this.param={
      cardBindFace:value.cardBindFace == 1 ? true : false,
      sipIsIssue:value.sipIsIssue == 1 ? true : false
     }
   }
  param:object;
  id:string;

  schema:SFSchema={
    properties:{
      cardBindFace: {
        type: 'boolean',
        title: '卡和人脸绑定',
        ui: {
          checkedChildren: '是',
          unCheckedChildren: '否',
        },
      },
      sipIsIssue:{
        type:'boolean',
        title:'呼叫开关',
        ui:{
          checkedChildren:'开',
          unCheckedChildren:'关'
        }
      }
    },
    ui:{
      spanLabel:10,
      spanControl:14
    }
  }
  constructor(
    private msg: NzMessageService,
    private modalRef: NzModalRef,
    private area: AreaService,
    private http: _HttpClient,
    private api: ApiService
  ) { }

  ngOnInit() {
  }

  submit(data:any) : void {
    let cardBindFace= data.cardBindFace == true ? 1 : 0 ;
    let sipIsIssue = data.sipIsIssue == true ? 1 : 0 ;
    const body={cardBindFace:cardBindFace,sipIsIssue:sipIsIssue};
    this.http.request("put",this.api.area.update.url+ `/${ this.id }`,{body}).subscribe((res:any)=>{
      if(res.status == 200){  
        this.msg.success(res.message);
        this.modalRef.triggerOk();
      }else{
        this.msg.error(res.message);
      }
    })
  }

}
